#include "list.h"

#include <stdlib.h>
#include <string.h>


slist *slist_new()
{
	slist *list=malloc(sizeof(node));
	if(list){
		memset(list, 0, sizeof(node));
	}
	return list;
}

void slist_free(slist *list)
{
	if(list){
		node *nodeIndex = (node*)list;
		while(nodeIndex){
			node *nodeNext = nodeIndex->next;
			free(nodeIndex->data);
			free(nodeIndex);
			nodeIndex = nodeNext;
		}
	}
}

int slist_len(slist *list)
{
	int nLen = 0;
	if(list){
		node *nodeIndex = (node*)list;
		while(nodeIndex->next){
			nodeIndex = nodeIndex->next;
			nLen++;
		}
	}
	return nLen;
}

int slist_push_back(slist *list, void *data)
{
	node *nodeNew =	malloc(sizeof(node));
	if(nodeNew){
		memset(nodeNew, 0, sizeof(nodeNew));
		nodeNew->data = data;

		node *nodeIndex=(node*)list;
		for(; nodeIndex->next; nodeIndex=nodeIndex->next){
		}
		nodeIndex->next = nodeNew;
	}
	else{
		return 1;
	}
	return 0;
}
